{\rtf1\ansi\ansicpg1252\uc1\deff36\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1036\deflangfe1036{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fswiss\fcharset0\fprq2{\*\panose 020b0604020202020204}Arial;}
{\f2\fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;}{\f36\fswiss\fcharset0\fprq2{\*\panose 020b0604030504040204}Tahoma;}{\f37\froman\fcharset238\fprq2 Times New Roman CE;}{\f38\froman\fcharset204\fprq2 Times New Roman Cyr;}
{\f40\froman\fcharset161\fprq2 Times New Roman Greek;}{\f41\froman\fcharset162\fprq2 Times New Roman Tur;}{\f42\froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f43\froman\fcharset178\fprq2 Times New Roman (Arabic);}
{\f44\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f45\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f47\fswiss\fcharset238\fprq2 Arial CE;}{\f48\fswiss\fcharset204\fprq2 Arial Cyr;}{\f50\fswiss\fcharset161\fprq2 Arial Greek;}
{\f51\fswiss\fcharset162\fprq2 Arial Tur;}{\f52\fswiss\fcharset177\fprq2 Arial (Hebrew);}{\f53\fswiss\fcharset178\fprq2 Arial (Arabic);}{\f54\fswiss\fcharset186\fprq2 Arial Baltic;}{\f55\fswiss\fcharset163\fprq2 Arial (Vietnamese);}
{\f57\fmodern\fcharset238\fprq1 Courier New CE;}{\f58\fmodern\fcharset204\fprq1 Courier New Cyr;}{\f60\fmodern\fcharset161\fprq1 Courier New Greek;}{\f61\fmodern\fcharset162\fprq1 Courier New Tur;}{\f62\fmodern\fcharset177\fprq1 Courier New (Hebrew);}
{\f63\fmodern\fcharset178\fprq1 Courier New (Arabic);}{\f64\fmodern\fcharset186\fprq1 Courier New Baltic;}{\f65\fmodern\fcharset163\fprq1 Courier New (Vietnamese);}{\f397\fswiss\fcharset238\fprq2 Tahoma CE;}{\f398\fswiss\fcharset204\fprq2 Tahoma Cyr;}
{\f400\fswiss\fcharset161\fprq2 Tahoma Greek;}{\f401\fswiss\fcharset162\fprq2 Tahoma Tur;}{\f402\fswiss\fcharset177\fprq2 Tahoma (Hebrew);}{\f403\fswiss\fcharset178\fprq2 Tahoma (Arabic);}{\f404\fswiss\fcharset186\fprq2 Tahoma Baltic;}
{\f405\fswiss\fcharset163\fprq2 Tahoma (Vietnamese);}{\f406\fswiss\fcharset222\fprq2 Tahoma (Thai);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;
\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{
\qj \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \f36\fs20\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 \snext0 \styrsid8725272 Normal;}{
\s2\qj \li0\ri0\sb240\sa60\keepn\widctlpar\aspalpha\aspnum\faauto\outlinelevel1\adjustright\rin0\lin0\itap0 \b\i\f1\fs28\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 \sbasedon0 \snext0 \styrsid8725272 heading 2;}{\*\cs10 \additive \ssemihidden 
Default Paragraph Font;}{\*\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv 
\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}{\s15\qj \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 
\f2\fs20\lang1033\langfe1036\cgrid\langnp1033\langfenp1036 \sbasedon0 \snext15 \slink16 \styrsid8725272 Code;}{\*\cs16 \additive \f2\lang1033\langfe1036\langnp1033\langfenp1036 \sbasedon10 \slink15 \slocked \styrsid8725272 Code Car;}}
{\*\latentstyles\lsdstimax156\lsdlockeddef0}{\*\rsidtbl \rsid3615657\rsid6312873\rsid7168543\rsid8725272\rsid9764884\rsid10836819\rsid15692682}{\*\generator Microsoft Word 11.0.6502;}{\info
{\title About the differences between Direct3D and Managed Direct3D}{\author Eric Nowinski}{\operator Eric Nowinski}{\creatim\yr2005\mo8\dy28\hr10\min57}{\revtim\yr2005\mo8\dy29\hr10\min7}{\version3}{\edmins12}{\nofpages2}{\nofwords437}{\nofchars2405}
{\*\company Personal Copy}{\nofcharsws2837}{\vern24579}}\paperw11907\paperh16840\margl1418\margr1418\margt1418\margb1418 
\deftab708\widowctrl\ftnbj\aenddoc\hyphhotz425\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1418\dgvorigin1418\dghshow1\dgvshow1
\jexpand\viewkind1\viewscale100\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct
\asianbrkrule\rsidroot8725272\newtblstyruls\nogrowautofit \fet0\sectd \psz9\linex0\headery709\footery709\colsx708\endnhere\sectlinegrid360\sectdefaultcl\sectrsid15692682\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2
\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6
\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang 
{\pntxtb (}{\pntxta )}}\pard\plain \s2\qj \li0\ri0\sb240\sa60\keepn\widctlpar\aspalpha\aspnum\faauto\outlinelevel1\adjustright\rin0\lin0\itap0\pararsid8725272 \b\i\f1\fs28\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 {
\lang1033\langfe1036\langnp1033\insrsid8725272 About the differences between Direct3D and Managed Direct3D
\par }\pard\plain \qj \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 \f36\fs20\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 {\lang1033\langfe1036\langnp1033\insrsid8725272 
\par To simplify, Managed Direct3D is just a collection of wrapper classes over unmanaged COM objects.
\par 
\par The immediate impact of this fact is that a Managed Direct3D object is not a binary equivalent of its unmanaged counterpart.
\par 
\par Managed Direct3D and Direct3D are two different worlds but bridges between them exist! Managed Di}{\lang1033\langfe1036\langnp1033\insrsid3615657 r}{\lang1033\langfe1036\langnp1033\insrsid8725272 
ect3D objects offer methods to retrieve the underlying unmanaged Direct3D object and methods to create Managed Direct3D object}{\lang1033\langfe1036\langnp1033\insrsid3615657 s}{\lang1033\langfe1036\langnp1033\insrsid8725272 
 from unmanaged Direct3D objects.
\par 
\par Mixing Unmanaged Direct3D and Managed Direct3D is not supported by Microsoft.
\par 
\par }\pard\plain \s2\qj \li0\ri0\sb240\sa60\keepn\widctlpar\aspalpha\aspnum\faauto\outlinelevel1\adjustright\rin0\lin0\itap0\pararsid8725272 \b\i\f1\fs28\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 {\lang1033\langfe1036\langnp1033\insrsid8725272 
Mixing Direct3D and Managed Direct3D
\par }\pard\plain \qj \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 \f36\fs20\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 {\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid10836819 
\par Most Managed Direct3D objects (}{\lang1033\langfe1036\langnp1033\insrsid8725272 like Device, Surface }{\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid10836819 or Texture) expose a }{
\cs16\f2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid10836819 GetObjectByValue}{\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid10836819  method, taking a magic number as input and return}{\lang1033\langfe1036\langnp1033\insrsid8725272 
ing}{\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid10836819  an unmanaged pointer of the wrapped unmanaged object. All objects supporting the }{\cs16\f2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid10836819 GetObjectByValue}{
\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid10836819  method use the same }{\lang1033\langfe1036\langnp1033\insrsid8725272 magic number.}{\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid10836819 
\par 
\par }\pard \qj \fi540\li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 {\b\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid9764884 Example: Retrieve }{\b\lang1033\langfe1036\langnp1033\insrsid8725272 an }{
\b\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid9764884 unmanaged Device from a managed one
\par }{\lang1033\langfe1036\langnp1033\insrsid8725272 
\par }\pard\plain \s15\qj \fi540\li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 \f2\fs20\lang1033\langfe1036\cgrid\langnp1033\langfenp1036 {\cf2\insrsid8725272 private}{\insrsid8725272  }{\cf2\insrsid8725272 const}{
\insrsid8725272  }{\cf2\insrsid8725272 int}{\insrsid8725272  DxMagicNumber = -759872593;}{\insrsid8725272\charrsid9764884 
\par }{\cf2\insrsid8725272 private}{\insrsid8725272  Device device = }{\cf2\insrsid8725272 null}{\insrsid8725272 ;
\par ...
\par // Assume a managed device ha}{\insrsid3615657 s}{\insrsid8725272  been created
\par ...
\par IntPtr unmanagedDevice = device.GetObjectByValue(DxMagicNumber);
\par }\pard\plain \qj \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 \f36\fs20\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 {\lang1033\langfe1036\langnp1033\insrsid8725272 
\par It is possible to create a managed object from an unmanaged Direct3D pointer through their constructors. Not all objects can be created like this, but the most important ones can. Please consult the Managed Direct3D documentation.
\par 
\par Special care must be taken on COM object reference count. When a Managed Direct3D object is disposed, it also releases its underlying COM Direct3D object. So if the managed o
bject must not impact the unmanaged one, the COM interface must be "AddRefed" before being passed to the Managed Constructor. As a last warning, the various versions of Managed DirectX act differently regarding the AddRef of unmanaged pointers. In the fir
st Managed DirectX release, AddRef was done in the constructor but this is no longer the case in the latest release}{\lang1033\langfe1036\langnp1033\insrsid6312873  (presumably starting with DX9.0b)}{\lang1033\langfe1036\langnp1033\insrsid8725272 .
\par 
\par }\pard \qj \fi540\li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 {\b\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 Example: Create a managed surface from an unmanaged pointer
\par }{\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 
\par }\pard\plain \s15\qj \fi540\li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 \f2\fs20\lang1033\langfe1036\cgrid\langnp1033\langfenp1036 {\cf2\insrsid8725272 private}{\insrsid8725272  IntPtr }{
\insrsid8725272\charrsid7168543 unmanagedSurface}{\insrsid8725272 ;
\par ...
\par }\pard\plain \qj \fi540\li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 \f36\fs20\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 {\f2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 // }{
\f2\lang1033\langfe1036\langnp1033\insrsid8725272 Assume }{\f2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 unmanagedSurface}{\f2\lang1033\langfe1036\langnp1033\insrsid8725272  is a valid }{
\f2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 IDirect3DSurface9}{\f2\lang1033\langfe1036\langnp1033\insrsid8725272  pointer}{\f2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 
\par }{\f2\lang1033\langfe1036\langnp1033\insrsid8725272 ...
\par }{\f2\insrsid8725272 Marshal.AddRef(}{\f2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 unmanagedSurface}{\f2\insrsid8725272 );}{\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 
\par }{\f2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 surface = }{\f2\cf2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 new}{\f2\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543  Surface(unmanagedSurface);}{
\lang1033\langfe1036\langnp1033\insrsid8725272\charrsid7168543 
\par }\pard \qj \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 {\lang1033\langfe1036\langnp1033\insrsid8725272 
\par }\pard\plain \s2\qj \li0\ri0\sb240\sa60\keepn\widctlpar\aspalpha\aspnum\faauto\outlinelevel1\adjustright\rin0\lin0\itap0\pararsid8725272 \b\i\f1\fs28\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 {\lang1033\langfe1036\langnp1033\insrsid8725272 
A note about performance
\par }\pard\plain \qj \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8725272 \f36\fs20\lang1036\langfe1036\cgrid\langnp1036\langfenp1036 {\lang1033\langfe1036\langnp1033\insrsid8725272 
\par Instantiating Managed Direct3D object is time and memory costly. For instance, it is definitely not a good idea to create a new managed surface each time a frame must be displayed.
\par For better performance, it's very important to create Managed objects only once. This is not as undoable as it sound because unmanaged code doesn't have a garbage collector that moves objects in memo
ry. When a COM object is created at a memory location, it stays }{\lang1033\langfe1036\langnp1033\insrsid3615657 t}{\lang1033\langfe1036\langnp1033\insrsid8725272 
here until it effectively dies. An unmanaged Direct3D object pointer can easily serve as a key in a Hashtable for example.
\par 
\par }\pard \qj \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 {\insrsid8725272 
\par }}